
#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;

void test_vector()
{
    std::vector<int> v = {1,2,3,4,5,6,7,8};

    for (auto i:v)
    {
        cout << i << endl;
    }

    for (std::vector<int>::iterator it = v.begin();it != v.end();it++)
    {
        cout << *it << endl;
    }

}

template<typename T>
void bubbleSort(typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end)
{
    if (begin == end)
    {
        return;
    }

    for (auto i = begin;i != end-1;i++)
    {
        int count = 0;
        // 第一轮排序将最大的值移动到最右边
        for (auto j = begin;j != end-1;j++)
        {
            if (*j > *(j+1))
            {
                swap(*j,*(j+1));
                count = 1;
            }
            
        }

        if (count == 0)
        {
            break;
        }
    }
}

int main() {
    std::vector<int> v =  {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5};
    bubbleSort<int>(v.begin(), v.end());
    for (auto i : v) {
        std::cout << i << " ";
    }
    std::cout << std::endl;
    return 0;
}









